﻿//-----------------------------------------------------------------------
// <copyright file="UsageStatistics.cs" company="Redmist">
//     Copyright (c) Damien T Smith. All rights reserved.
// </copyright>
// <author>Damien Smith</author>
//-----------------------------------------------------------------------

namespace Redmist.UsageMonitor.UsageData
{
    /// <summary>Stores basic usage statistics for a billing period.</summary>
    public class UsageStatistics
    {
        /// <summary>Initializes a new instance of the UsageStatistics class.</summary>
        /// <param name="peak">The amount of peak data consumed so far during the billing period.</param>
        /// <param name="countedOffPeak">The amount of counted off peak data consumed so far during the billing period.</param>
        public UsageStatistics(int peak, int countedOffPeak)
        {
            this.Peak = peak;
            this.CountedOffPeak = countedOffPeak;
        }

        /// <summary>Gets the amount of peak data consumed so far during the billing period.</summary>
        public int Peak { get; private set; }

        /// <summary>Gets the amount of counted off peak data consumed so far during the billing period.</summary>
        public int CountedOffPeak { get; private set; }

        /// <summary>Adds two usage statistics collections and return the summed result.</summary>
        /// <param name="firstUsage">A Redmist.UsageMonitor.UsageData.UsageStatistics representing the first collection.</param>
        /// <param name="secondUsage">A Redmist.UsageMonitor.UsageData.UsageStatistics representing the second collection.</param>
        /// <returns>A Redmist.UsageMonitor.UsageData.UsageStatistics representing the summed result.</returns>
        public static UsageStatistics AddUsage(UsageStatistics firstUsage, UsageStatistics secondUsage)
        {
            return new UsageStatistics(firstUsage.Peak + secondUsage.Peak, firstUsage.CountedOffPeak + secondUsage.CountedOffPeak);
        }

        /// <summary>Compares two usage statistics collections and returns the greater of the two.</summary>
        /// <param name="firstUsage">A Redmist.UsageMonitor.UsageData.UsageStatistics representing the first collection.</param>
        /// <param name="secondUsage">A Redmist.UsageMonitor.UsageData.UsageStatistics representing the second collection.</param>
        /// <returns>A Redmist.UsageMonitor.UsageData.UsageStatistics representing the greater usage.</returns>
        public static UsageStatistics FindGreaterUsage(UsageStatistics firstUsage, UsageStatistics secondUsage)
        {
            if (firstUsage.Peak + firstUsage.CountedOffPeak > secondUsage.Peak + secondUsage.CountedOffPeak)
            {
                return firstUsage;
            }

            return secondUsage;
        }
    }
}
